﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Enterprise.UI.Web.Modules.Kaifa
{
    public partial class Danwei : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }

        }

        private void BindGrid()
        {
            Enterprise.Service.Kaifabu.DanweiService dws = new Service.Kaifabu.DanweiService();
            GridView1.DataSource=  dws.GetList("");
            GridView1.DataBind();
        }        

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            tb_dwmc.ReadOnly = true;
            tb_dwmc.Text = GridView1.SelectedRow.Cells[0].Text;
            tb_dwmcru.Text = GridView1.SelectedRow.Cells[1].Text;
        }

        protected void btn_new_Click(object sender, EventArgs e)
        {
            tb_dwmc.ReadOnly = false;
            Enterprise.Service.Kaifabu.DanweiService dws = new Service.Kaifabu.DanweiService();
            dws.Add(tb_dwmc.Text, tb_dwmcru.Text);
            Response.Redirect("danwei.aspx", true);
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            Enterprise.Service.Kaifabu.DanweiService dws = new Service.Kaifabu.DanweiService();
            if (tb_dwmc.Text != "")
            {               
                dws.Update(tb_dwmc.Text, tb_dwmcru.Text);
            }
            else
            {
                dws.Add(tb_dwmc.Text, tb_dwmcru.Text);
            }            
        }
        
    }
}